package com.ruoyi.zhjd.laboratory.modules.laboratorymechanics.controller;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.zhjd.laboratory.modules.laboratorymechanics.dto.LaboratoryMechanicsPressMachineDto;
import com.ruoyi.zhjd.laboratory.modules.laboratorymechanics.service.LaboratoryMechanicsPressMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName LaboratoryMechanicsPressMachineController
 * @Description 压力机
 * @author cuiwenlong
 * @since 2023-07-10
 */
@RestController
@RequestMapping("/api/laboratoryMechanicsPressMachine")
public class LaboratoryMechanicsPressMachineController {

	@Autowired
	private LaboratoryMechanicsPressMachineService service;

	/**
     * @Title: page
     * @Description: 沥青类技术要求分页列表
     * @param params 查询条件
     * @return Result 沥青类技术要求分页列表
     */
    @GetMapping("page")
    public R<IPage<LaboratoryMechanicsPressMachineDto>> page(@RequestParam Map<String, Object> params) {
        IPage<LaboratoryMechanicsPressMachineDto> page = service.page(params);
        return R.ok(page);
    }

	/**
     * 设备数据上传
     */
    @PostMapping("/Upload")
    public Map<String, Object> Upload(@RequestBody JSONObject json){
    	Map<String, Object> resultMap = service.Upload(json);
		return resultMap;
    }

    /**
     * 设备数据上传
     */
    @PostMapping("/dataBaseUpload")
    public String dataBaseUpload(@RequestBody JSONObject json){
    	Integer key = null;
    	JSONObject result = new JSONObject();
    	try {
			if ("W".equals(json.get("deviceType"))){
				key = service.saveDataBaseUpload(json);
			} else if ("Y".equals(json.get("deviceType"))) {
				key = service.saveDataBaseUploadPress(json);
			}else if("OUK".equals(json.get("deviceType"))){
				key = service.saveDataBaseUploadOUKPress(json);
			}else if("FYW".equals(json.get("deviceType"))){
				key = service.saveDataBaseUploadFYAllPurpose(json);
			}else {
				result.put("code", 300);
				return result.toString();
			}
			result.put("code", 200);
    		result.put("data", key+"");
		} catch (Exception e) {
			result.put("code", 300);
		}
    	return result.toString();
    }

}
